package com.common.tool;

import cn.hutool.json.JSONConfig;
import cn.hutool.json.JSONUtil;
import com.common.domain.pojo.Result;
import jakarta.servlet.http.HttpServletResponse;


import java.io.IOException;

public class ResponseTool {

    public static void result(HttpServletResponse response,Integer code , String json) {
        response.setContentType("application/json");
        response.setStatus(code);
        response.setCharacterEncoding("utf-8");
        try {
            response.getWriter().write(json);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static void result(HttpServletResponse response, Integer code , Result json) {
        response.setContentType("application/json");
        response.setStatus(code);
        response.setCharacterEncoding("utf-8");
        try {
            response.getWriter().write(JSONUtil.toJsonStr(json,new JSONConfig().setIgnoreNullValue(false)));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
